window.onload = function () {
	var xhr_ip = new XMLHttpRequest() || new ActiveXObject("Microsoft.XMLHTTP");
	xhr_ip.onreadystatechange = function () {
		if (xhr_ip.readyState == 4 && xhr_ip.status == 200) {
			var oNode = document.createElement("p"),
			data = JSON.parse(xhr_ip.responseText.split("(")[1].split(")")[0]);
			console.log(data);
			oNode.innerHTML = '<a href="'+location.protocol+'//nova.wodemo.'+location.hostname.split('.')[location.hostname.split('.').length-1]+'/ip" class="ip-lite">' + data.ip + '&nbsp;&nbsp;&nbsp;' + data.city + ',' + data.region + ',' + data.country + "</a>";
			var contain = document.querySelector("div.wo-search-form~p");
			if(contain === null){
				contain = document.querySelector("div.wo-search-form");
				contain.parentNode.insertBefore(oNode, contain.nextSibling.nextSibling.nextSibling);
				contain.nextSibling.nextSibling.remove();
				console.log(contain.nextSibling);
			}
			else{
				if (contain.textContent === '\n' || contain.textContent === '') {
					contain.innerHTML = oNode.innerHTML;
					contain.nextSibling.nextSibling.remove();
					contain.nextSibling.nextSibling.nextSibling.remove();
					console.log(contain.nextSibling.nextSibling);
					console.log(contain.nextSibling.nextSibling.nextSibling);
				} else {
					contain.parentNode.insertBefore(oNode, contain.nextSibling.nextSibling.nextSibling);
					contain.nextSibling.nextSibling.remove();
					console.log(contain.nextSibling);
				}
			}
		}
	}
	xhr_ip.open("GET", "https://ipinfo.io/?callback=handle");
	xhr_ip.send();
	function refresh(){
		var xhr_wd = new XMLHttpRequest() || new ActiveXObject("Microsoft.XMLHTTP")
		xhr_wd.onreadystatechange = function(){
			if(xhr_wd.readyState == 4 && xhr_wd.status == 200){
				var oBox = document.querySelector("div.wo-search-form>form>input[name='q']");
				//oBox.placeholder = "搜索框说:\"" + JSON.parse(xhr_wd.response)["text"] + "\"    source:" + JSON.parse(xhr_wd.response)["source"];
				oBox.placeholder = "搜索框说: \"" + JSON.parse(xhr_wd.response)["text"] + "\"";
				oBox.onblur= refresh;
			}
		}
		xhr_wd.open("GET","https://api.i-meto.com/hitokoto?encode=json");
		xhr_wd.send();
	}
	refresh();
}
